package com.ciaojian.worker.controller;

import com.ciaojian.core.util.Result;
import com.ciaojian.miniapp.api.ProfitSharingApi;
import com.ciaojian.miniapp.model.request.profitsharing.ProfitSharing;
import com.ciaojian.miniapp.model.request.profitsharing.ProfitsSharingReceiver;
import com.ciaojian.miniapp.model.response.profitsharing.ProfitSharingResponse;
import com.ciaojian.worker.pay.WxPayBean;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Atlakyn
 */
@Api(tags = "分佣相关")
@RestController
@RequestMapping("/profit-sharing")
public class ProfitSharingController {
    @Resource
    private WxPayBean wxPayBean;

    @GetMapping("/withdraw")
    public Result applyWithdraw(String transactionId, String orderNo) {
        List<ProfitsSharingReceiver> receiverList = new ArrayList<>();
        ProfitsSharingReceiver receiver = ProfitsSharingReceiver.builder()
                .type("PERSONAL_OPENID")
                .account("")
                .amount(1)
                .description("销售分佣")
                .build();
        receiverList.add(receiver);
        ProfitSharing build = ProfitSharing.builder()
                .appid(wxPayBean.getAppId())
                .transaction_id(transactionId)
                .out_order_no(orderNo)
                .receivers(receiverList).build();
        try {
            ProfitSharingApi.profitSharing(build, ProfitSharingResponse.class);
        } catch (JsonProcessingException e) {

            e.printStackTrace();
        }
        return Result.ok();
    }
}
